kmpkg_from_gitee(
    OUT_SOURCE_PATH SOURCE_PATH
    REPO kumo-hub/OpenCL-SDK
    REF "${VERSION}"
    SHA512 1dc341df91c8b88f12580c81f90c67225ece5ce9c093d528c967c8436c991b1abf1dc65e08afe2fc00ee86bb146ec1429981eb69e2346b61ca69c7ac62310681
    HEAD_REF main
)

kmpkg_from_gitee(
    OUT_SOURCE_PATH OPENCL_HEADERS
    REPO kumo-hub/OpenCL-Headers
    REF "${VERSION}"
    SHA512 36eef3191c698b76412ce71455e31e322ad635a9a2a69dd496692023ee56022ba65226607fdd286667f6650019b0e2b79813bbd1e973ca46638ab13639782ccc
    HEAD_REF main
)
if(NOT EXISTS "${SOURCE_PATH}/external/OpenCL-Headers/CMakeLists.txt")
    file(REMOVE_RECURSE "${SOURCE_PATH}/external/OpenCL-Headers")
    file(RENAME "${OPENCL_HEADERS}" "${SOURCE_PATH}/external/OpenCL-Headers")
endif()

kmpkg_from_gitee(
    OUT_SOURCE_PATH OPENCL_CLHPP
    REPO kumo-hub/OpenCL-CLHPP
    REF "${VERSION}"
    SHA512 017d0e69aee5f1d45976eac665a07de3aa7ef49f622821df0d29d5efff71bf3708378badc51e510b2725e0f860e230e90bd256d37d69cd7f5d31c973ed4a49fe
    HEAD_REF main
)
if(NOT EXISTS "${SOURCE_PATH}/external/OpenCL-CLHPP/CMakeLists.txt")
    file(REMOVE_RECURSE "${SOURCE_PATH}/external/OpenCL-CLHPP")
    file(RENAME "${OPENCL_CLHPP}" "${SOURCE_PATH}/external/OpenCL-CLHPP")
endif()

kmpkg_from_gitee(
    OUT_SOURCE_PATH OPENCL_ICD_LOADER
    REPO kumo-hub/OpenCL-ICD-Loader
    REF "${VERSION}"
    SHA512 b1107f56c7756d6700366115acaf869e7452e6ad3fa855d57333b41209eb9197d0cbeaf6be7a9decb5aa8b8ee97d690f2cd09a13854b5e2ec429dc5bd59f32d2
    HEAD_REF main
)
if(NOT EXISTS "${SOURCE_PATH}/external/OpenCL-ICD-Loader/CMakeLists.txt")
    file(REMOVE_RECURSE "${SOURCE_PATH}/external/OpenCL-ICD-Loader")
    file(RENAME "${OPENCL_ICD_LOADER}" "${SOURCE_PATH}/external/OpenCL-ICD-Loader")
endif()

kmpkg_from_gitee(
    OUT_SOURCE_PATH WHEREAMI
    REPO kumo-hub/whereami
    REF f5e3eac441acbb4ec1fe3e2c32646248ae463398 # 2024-06-09
    SHA512 d6fa8b6788cabdbb185a6ffba79c994762924a1c60595b769a7d3bb4a3ddf0f80cdeac7bd915cffa720f9123a720a1b7f0023fd7f2cf58906d15758529a99e2d
    HEAD_REF master
)
kmpkg_replace_string("${SOURCE_PATH}/cmake/Dependencies/whereami/whereami.cmake" [[${CMAKE_CURRENT_BINARY_DIR}/_deps/whereami-external-src]] [[${whereami-external_SOURCE_DIR}]])

kmpkg_cmake_configure(
    SOURCE_PATH "${SOURCE_PATH}"
    OPTIONS
        "-DFETCHCONTENT_SOURCE_DIR_WHEREAMI-EXTERNAL=${WHEREAMI}"
        -DBUILD_DOCS=OFF
        -DBUILD_EXAMPLES=OFF
        -DBUILD_TESTING=OFF
        -DOPENCL_HEADERS_BUILD_CXX_TESTS=OFF
        -DOPENCL_SDK_BUILD_SAMPLES=OFF
)
kmpkg_cmake_install()
kmpkg_cmake_config_fixup(CONFIG_PATH "share/cmake/OpenCLHeaders" PACKAGE_NAME "OpenCLHeaders" DO_NOT_DELETE_PARENT_CONFIG_PATH)
kmpkg_cmake_config_fixup(CONFIG_PATH "share/cmake/OpenCLICDLoader" PACKAGE_NAME "OpenCLICDLoader" DO_NOT_DELETE_PARENT_CONFIG_PATH)
kmpkg_cmake_config_fixup(CONFIG_PATH "share/cmake/OpenCLHeadersCpp" PACKAGE_NAME "OpenCLHeadersCpp" DO_NOT_DELETE_PARENT_CONFIG_PATH)
kmpkg_cmake_config_fixup(CONFIG_PATH "share/cmake/OpenCLUtils" PACKAGE_NAME "OpenCLUtils" DO_NOT_DELETE_PARENT_CONFIG_PATH)
kmpkg_cmake_config_fixup(CONFIG_PATH "share/cmake/OpenCLUtilsCpp" PACKAGE_NAME "OpenCLUtilsCpp" DO_NOT_DELETE_PARENT_CONFIG_PATH)
kmpkg_cmake_config_fixup(CONFIG_PATH "share/cmake/OpenCL" PACKAGE_NAME "opencl")
kmpkg_fixup_pkgconfig()
kmpkg_copy_pdbs()
kmpkg_copy_tools(TOOL_NAMES cllayerinfo AUTO_CLEAN)

file(REMOVE_RECURSE
    "${CURRENT_PACKAGES_DIR}/debug/include"
    "${CURRENT_PACKAGES_DIR}/debug/share"
)

configure_file("${CMAKE_CURRENT_LIST_DIR}/kmpkg-cmake-wrapper.cmake" "${CURRENT_PACKAGES_DIR}/share/${PORT}/kmpkg-cmake-wrapper.cmake" @ONLY)

file(COPY "${CMAKE_CURRENT_LIST_DIR}/usage" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}")
kmpkg_install_copyright(FILE_LIST "${SOURCE_PATH}/LICENSE" "${WHEREAMI}/LICENSE.MIT"
    COMMENT [[
The OpenCL SDK is licensed under the terms of the Apache-2.0 license.
The OpenCL Utility Library uses code from https://github.com/gpakosz/whereami
which is dual licensed under both the WTFPLv2 and MIT licenses.
]])
